// 修改 webpack 配置
const { override, addWebpackAlias, addWebpackModuleRule, addLessLoader, adjustStyleLoaders } = require("customize-cra");
const path = require("path");


module.exports = override(
    //增加路径别名的处理
    addWebpackAlias({
        '@': path.resolve(__dirname, './src')
    }),
    (config, env) => {
        if (env === 'development') {
            // 开发环境使用 eval-source-map
            config.devtool = 'eval-source-map';
        }
        return config;
    },
    addWebpackModuleRule({
        test: /\.svg$/,
        use: ['@svgr/webpack'],
    }),
    // 需要安装 style-loader css-loader less less-loader postcss postcss-loader
    addLessLoader({
        lessOptions: {
            javascriptEnabled: true,
            cssModules: {
                localIdentName: '[path][name]__[local]--[hash:base64:5]',
            }
        },
    }),
    // 解决引入less报错
    adjustStyleLoaders(({ use: [, , postcss] }) => {
        const postcssOptions = postcss.options;
        postcss.options = { postcssOptions };
    }),

);


